#include "comm/config.h"

#include <json/json.h>

using namespace nymphaea::comm;


Config::Config(): mpRoot(NULL), illegal(false)
{
	mpRoot = new Json::Value;
}

Config::Config(Json::Value node): mpRoot(NULL), illegal(false)
{
	mpRoot = new Json::Value(node);
}

Config::~Config()
{
	delete mpRoot;
}

int Config::load(const std::string& dump)
{
	/*
	 * All data will store in the first element;
	 */
	static Json::Reader reader;

	if(!reader.parse(dump, *mpRoot)){
		return -1;
	}

	return 0;

}
	
Config Config::getChild(const std::string& name) const
{
	Config res;
	if(!mpRoot->isMember(name)){
		res.illegal = true;
	}else{
		res = Config(mpRoot->get(name, "NULL"));
	}
	return res;
}

const std::string Config::getAttribute(const std::string& name) const
{
	return std::string();
}


